<?include_once('conn.php');?>
<html>
<head>
<?include_once('inc_head.php');?>
<?
$act=$_GET['act'];
$ListName=TABLE_C."vote_series"; //要操作的表名
switch($act)
{
//'''''''''''''''''''''''''''''''''''''''''''''''''''''''添加'''''''''''''''''''''''''''''''''''''''''''''''''''''''
case "add";
	$name=addslashes(trim($_POST['name']));
	$forid=$_POST['forid'];
	#插入数据库
	$cmd="insert into $ListName(name,forid)values('$name',$forid)";
	if(mysql_query($cmd) or die(mysql_error())){
		gourl('添加成功',$cururl);
	}
	exit;
	break;


	//'''''''''''''''''''''''''''''''''''''''''''''''''''''''删除'''''''''''''''''''''''''''''''''''''''''''''''''''''''
case "del";
	$id=intval($_GET["id"]);
	$imgf=$_GET['file'];
	$cmd="delete from $ListName where id=$id";
	
	#删除
	if(mysql_query($cmd) ){
	 gourl('删除成功！',$cururl);
	}
	exit;
	break;
//''''''''''''''''''''''''''''''''''''''''''''''''''''修改'''''''''''''''''''''''''''''''''''''''''''''''''''''''
case "editok";
	$id=intval($_POST["id"]);
	$name=rq('name');
	$price=intval(rq('price'));
	$payment=intval(rq('payment'));
	$active=intval(rq('active'));
	$rule=rq('rule');
	$evaluate_a=rq('evaluate_a');
	$evaluate_b=rq('evaluate_b');
	
	$cmd="update $ListName set name='$name',price=$price,rule='$rule',payment=$payment,active=$active,evaluate_a='$evaluate_a',evaluate_b='$evaluate_b' where id=$id";
	// exit;
	if(mysql_query($cmd) or die(mysql_error())){
	gourl('修改成功！',$cururl);
	}
	exit;
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?local("问卷管理");?>
<div id="intro">


<!-- //////////////////////////////////////////////////////////////////////  列表    ///////////////////////////////////////////////////////////////////////////////// -->
<!-- //////////////////////////////////////////////////////////////////////  列表    ///////////////////////////////////////////////////////////////////////////////// -->
<!-- //////////////////////////////////////////////////////////////////////  列表    ///////////////////////////////////////////////////////////////////////////////// -->
<!-- //////////////////////////////////////////////////////////////////////  列表    ///////////////////////////////////////////////////////////////////////////////// -->

<?if(strlen($act)==0){?>
<div class="local2"><b>添加</b></div>
<div style='padding:10px 0px;'>
	<form name="form1" method="post" class="flex flex-ai-c" action="?act=add"  enctype="multipart/form-data">
		<input type="text" name="name" class=' :required form-control' value="" placeholder="名称">
		<button type="submit" class="btn btn-primary btn-md">添加</button>
	</form>
</div>


<table class="table table-hover table-bordered table-striped" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
	<th>ID</th>
	<th width="300">名称</th>
	<th width="100">是否收费</th>
	<th width="100">是否开启</th>
	<th width="100">问卷类型</th>
	<th>操作</th>
</tr>
<?
/////////////////////////////////////1级循环///////////////////////////////////////
$mydbb=new mydb();
$mydbs=new mydb();
$datab=$mydbb->fetchAll("select * from ".$ListName." where forid=0 order by id");
for($i=0;$i<count($datab);$i++){
?>
	<tr>
		<td align="center"><?echo $datab[$i]['id'];?></td>
		<td><b> <?echo $datab[$i]['name'];?></b></td>
		<td> <? echo ($datab[$i]['payment'] ? "<span class=\"c-red\">￥{$datab[$i]['price']}</span>" :'<span class="c-green">免费</span>'); ?> </td>
		<td> <? echo ($datab[$i]['active'] ? '<span class="c-blue">开启</span>' :'<span class="c-999">关闭</span>'); ?> </td>
		<td><?echo $datab[$i]['type'];?> </td>
		<td>
		<form name="formadd" method="post" class="flex flex-ai-c" action="?act=add" style="margin:0px" enctype="multipart/form-data">
			<a href="admin_vote_series_edit.php?type=1&id=<?echo $datab[$i]['id']?>" rel="floatEdit" class="btn btn-xs btn-info">编辑</a>
			<!-- <? del($datab[$i]['id'],$datab[$i]['image']);?> -->
				添加：
				<input type="text" name="name" class=' :required form-control ' value="" size="12" placeholder="二级类别名称">
				<input type="hidden" name="forid" class='' value="<?echo $datab[$i]['id']?>" size="2" readonly>
				<button type="submit" class="btn btn-primary btn-small"  value="">添加2级类</button>
			</form>
		</td>
	</tr>
	<?
	/////////////////////////////////////2级循环///////////////////////////////////////
	$cmd2="select s.*,coalesce(l.num,0) num from ".$ListName." s left join (select id,series,count(0) num from ".TABLE_C."vote_question nums group by series) l on l.series=s.id where s.forid='{$datab[$i]['id']}'";
	$datas=$mydbs->fetchAll($cmd2);
	for($k=0;$k<count($datas);$k++){
	?>
		<tr>
			<td  align="center"><?echo $datas[$k]['id'];?></td>
			<td>&nbsp;&nbsp;├╍╍<a href="admin_vote_question.php?sid=<?echo $datas[$k]['id'];?>"><?echo $datas[$k]['name'];?></a>[<?echo $datas[$k]['num'];?></a>] </td>
			<td>-</td>
			<td>-</td>
			<td>-</td>
			<td>
				<div  class="flex flex-ai-c">
				<a href="admin_vote_series_edit.php?type=2&id=<?echo $datas[$k]['id'] ?>&forid=<?echo $datab[$i]['id'] ?>" rel="floatEdit" class="btn btn-xs btn-info">编辑</a>
				<span>规则：<?echo $datas[$k]['rule'] ?></span>
				<!-- <? del($datas[$k]['id'],$datas[$k]['image']);?> -->
				</div>
			</td>
		</tr>

	<?}//二级循环?>
<?}//一级循环 ?>
</table>
<? }?>
</div>
<? include('inc_foot.php');?>
</body>
</html>